<?php
namespace app\index\controller\wanlshop;

use app\common\controller\Wanlshop;
use think\Exception;

/**
 * 系统配置
 *
 * @icon   fa fa-cogs
 * @remark 可以在此增改系统的变量和分组,也可以自定义分组和变量,如果需要删除请从数据库中删除
 */
class Config extends Wanlshop
{
	
    /**
     * @var \app\common\model\Config
     */
	protected $noNeedLogin = '';
	protected $noNeedRight = '*';

    public function _initialize()
    {
        parent::_initialize();
        $this->model = model('app\index\model\wanlshop\ShopConfig');
        $typeList = $this->model->getTypeList();
        if($this->shop->state == 2){
            unset(
                $typeList['paylinx_wechat'],
                $typeList['paylinx_mobile_alipay'],
                $typeList['paylinx_pc_alipay'],
                $typeList['au_express']
            );
        }
		$this->view->assign("typeList",$typeList );
    }

    /**
     * 查看
     */
    public function index($type = '')
    {
        $row = $this->model->get(['shop_id' => $this->shop->id]);
		if(!$row){
			$this->model->shop_id = $this->shop->id;
			$this->model->save();
		}
		if ($this->request->isPost()) {
		    $params = $this->request->post("row/a");
            $paylinx_wechat = $this->request->post("paylinx_wechat/a");
            if($paylinx_wechat){
                $params['paylinx_wechat'] = json_encode($paylinx_wechat);
            }
            $paylinx_mobile_alipay = $this->request->post("paylinx_mobile_alipay/a");
            if($paylinx_mobile_alipay){
                $params['paylinx_mobile_alipay'] = json_encode($paylinx_mobile_alipay);
            }
            $paylinx_pc_alipay = $this->request->post("paylinx_pc_alipay/a");
            if($paylinx_pc_alipay){
                $params['paylinx_pc_alipay'] = json_encode($paylinx_pc_alipay);
            }
			$result = false;
			$result = $row->save($params);
			if ($result !== false) {
			    $this->success();
			} else {
			    $this->error(__('No rows were inserted'));
			}
		}
        $row['paylinx_wechat'] = json_decode($row['paylinx_wechat'],true);
        $row['paylinx_mobile_alipay'] = json_decode($row['paylinx_mobile_alipay'],true);
        $row['paylinx_pc_alipay'] = json_decode($row['paylinx_pc_alipay'],true);
		$this->view->assign('type', $type);
        $this->view->assign('row', $row);
        return $this->view->fetch();
    }

   
   

}
